<?php

$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$redis = require __DIR__ . '/redis.php';
$rules = require __DIR__ . '/rules.php';

$cur_date = date('Ymd');
$logfile = "@app/runtime/logs/app_{$cur_date}.log";

$config = [
    'id' => 'basic',
    'basePath' => dirname(__DIR__),
    'bootstrap' => ['log'],
    'language' => 'zh-CN',
    'aliases' => [
        '@bower' => '@vendor/bower-asset',
        '@npm'   => '@vendor/npm-asset',
    ],
    'components' => [
        'request' => [
            // !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
            'cookieValidationKey' => '_fTX15EpStPhvMoR4zcEkfm2_Ei6P-7G',
        ],
        'cache' => [
            'class' => 'yii\caching\FileCache',
        ],
        'redis' => $redis,
        'user' => [
            'identityClass' => 'app\models\User',
            'enableAutoLogin' => true,
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
//        sohu
//        'mailer' => [
//            'class' => 'yii\swiftmailer\Mailer',
//            'useFileTransport' => false,
//            'transport' => [
//                'class' => 'Swift_SmtpTransport',
//                'host' => 'mail.sohu.com',
//                'username' => 'yii2smtp@sohu.com',
//                'password' => 'Summer2015',
//                'port' => '25',
//                //'encryption' => 'ssl',
//            ],
//        ],

        'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'useFileTransport' =>false,//false发送邮件，true只是生成邮件在runtime文件夹下，不发邮件
            'transport' => [
                'class' => 'Swift_SmtpTransport',
                'host' => 'smtp.exmail.qq.com',
                'username' => 'system@apphz.cn',
                'password' => 'Summer2015',
                'port' => '465',
                'encryption' => 'ssl',
            ],
        ],
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                    'except' => [
                        'yii\web\HttpException:404',
                    ],
                    'logVars' => [],
                    'prefix' => function ($message) {
                        $uri = Yii::$app->request->url;
                        return "[$uri]";
                    },
                    'maxFileSize' => 1000000, //1GM
                    'logFile' => $logfile,
                ],
            ],
        ],
       'formatter' => [
            'dateFormat' => 'Y-M-d',
            'datetimeFormat' => 'php:Y-m-d H:i:s',
            'decimalSeparator' => ',',
            'thousandSeparator' => ' ',
            'currencyCode' => '￥',
            'sizeFormatBase' => 1000,
        ],
        'tool' => [
            'class' => 'app\components\Tool',
        ],
        'db' => $db,
        'urlManager' => [
            'class' => 'yii\web\UrlManager',
            'showScriptName' => false,
            'enablePrettyUrl' => true,
            'rules' => $rules
        ],
    ],
//    'modules' => [
//        'admin' => [
//            'class' => 'app\modules\admin\Module',
//        ]
//    ],
    'params' => $params,
];

if (YII_ENV_DEV) {
    // configuration adjustments for 'dev' environment
    $config['bootstrap'][] = 'debug';
    $config['modules']['debug'] = [
        'class' => 'yii\debug\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1', '::1', '47.91.254.250'],
    ];

    $config['bootstrap'][] = 'gii';
    $config['modules']['gii'] = [
        'class' => 'yii\gii\Module',
        // uncomment the following to add your IP if you are not connecting from localhost.
        'allowedIPs' => ['127.0.0.1', '::1', '47.91.254.250'],
    ];
}

if (IS_API_MODULES) {
    $config['defaultRoute'] = 'api/site/index';
}

if (MODULES_IS_MANAGE) {
    $config['components']['errorHandler'] = [
        'errorAction' => 'manage/site/error',
    ];
}

return $config;
